package com.example.basicsecurity.auth;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

/**
 * @author 罗俊华
 * @date 2021/11/9 - 5:48 下午
 */
@Slf4j
@Component
public class Auth {

    public boolean hasAuth(String s){

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).anyMatch((String authority)->{
            return s.equals(authority);
        });
    }

}
